Validator Utility
Install
npm i --save @darkwolf/validator
Usage
const validator = require('@darkwolf/validator')
validator.isNumber(13)
validator.isString(21)
const { Validator } = validator
new Validator(69).isString().isValid
new Validator(69).isNumber().isRange(0, 100).isValid
new Validator('69')
.isNumber()
.throw(() => new TypeError('Value must be a number'))
Init
new Validator(value?)
Methods
throw(() => e)
isRequired()
isOptional()
is(value => !!value)
isEqual(value1?, value2)
isStrictEqual(value1?, value2)
isType(value?, type)
isTag(value?, tag)
isInstance(value?, constructor)
isUndefined(value?)
isNull(value?)
isNil(value?)
isObject(value?)
isObjectLike(value?)
isPlainObject(value?)
isFunction(value?)
isBoolean(value?)
isNumber(value?)
isString(value?)
isSymbol(value?)
isArray(value?)
isBuffer(value?)
isArrayBuffer(value?)
isRegExp(value?)
isSet(value?)
isMap(value?)
isPromise(value?)
isDate(value?)
isError(value?)
isTypeError(value?)
isValidator(value?)
isCodeError(value?)
isNaN(value?)
isFinite(value?)
isInteger(value?)
isSafeInteger(value?)
isFloat(value?)
isDecimal(value?)
isInfinity(value?)
isMore(value?, number)
isLess(value?, number)
isMoreEqual(value?, number)
isLessEqual(value?, number)
isRange(value?, min, max)
isPositive(value?)
isNegative(value?)
isNonNegative(value?)
isNonPositive(value?)
isEven(value?)
isOdd(value?)
isTrue(value?)
isFalse(value?)
isRegex(value?, regex)
isExists(value?)
isLength(value?, number || ...[min, max])
isSize(value?, number || ...[min, max])
isEmpty(value?)
isHas(value?, key)
isIncludes(value1?, value2)
isIncluded(value1?, value2)
isUnique(value?)
isTimestamp(value?)
isUnixTimestamp(value?)
isUUID(value?)
isIPv4(value?)
isUrl(value?)
isEmail(value?)
isPhoneNumber(value?)
isASCII(value?)
isBase64(value?)
isBase64Url(value?)
isBase58(value?)
isJWT(value?)